package cn.jdk.aqstool;

import java.util.concurrent.CountDownLatch;

import lombok.extern.slf4j.Slf4j;

/**
 *
 * 计数器
 * @author summit
 * @since 2021/8/8 20:07
 */
@Slf4j
public class CountDownLatchTest {

	static CountDownLatch latch = new CountDownLatch(2);

	public static void main(String[] args) {
		new Thread(new Task1(latch), "thread-1").start();
		new Thread(new Task2(latch), "thread-2").start();

		try {
			// 当计数器减到0，继续往下执行，否则阻塞
			latch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			log.info("所有任务都完成");
		}

	}

}
